package com.cmcc.linlaker.ui.upload.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cmcc.linlaker.R;
import com.cmcc.linlaker.application.LinhuApp;
import com.cmcc.linlaker.bean.DictBean;
import com.cmcc.linlaker.ui.upload.bean.UploadQuestionBean;

import java.util.List;

public class UploadQuestionAdapter2 extends RecyclerView.Adapter<UploadQuestionAdapter2.ViewHolder> {

    private List<UploadQuestionBean.UploadQuestionData> itemList;
    private Context mContext;

    public UploadQuestionAdapter2(Context mContext, List<UploadQuestionBean.UploadQuestionData> itemList) {
        this.itemList = itemList;
        this.mContext = mContext;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.upload_question_item2, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        UploadQuestionBean.UploadQuestionData item = itemList.get(position);

        holder.text_title.setText(item.title);
        holder.text_big_problem.setText("建设方面：" + getBigProblemName(item.problemType));
        holder.text_small_problem.setText("巡查专题：" + item.problemClass);
    }

    private String getBigProblemName(String value) {
        for (DictBean.DictData data : LinhuApp.problemTypeList) {
            if (value.equals(data.dictValue)) {
                return data.dictLabel;
            }
        }

        return "";
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public int getItemCount() {
        return itemList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        public TextView text_title, text_big_problem, text_small_problem;


        public ViewHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(this);

            text_title = itemView.findViewById(R.id.text_title);
            text_big_problem = itemView.findViewById(R.id.text_big_problem);
            text_small_problem = itemView.findViewById(R.id.text_small_problem);
        }

        @Override
        public void onClick(View v) {
            onItemClickListener.onItemClick(getAdapterPosition());
        }
    }

}

